package com.dx.wlmq.controller;

import com.alibaba.fastjson.JSON;
import com.dx.wlmq.domain.OrSupplier;
import com.dx.wlmq.service.OrSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName OrSupplierControllers
 * @Description TODO:
 * @Author 12994
 * @Date 2024/10/20 19:07
 * @Version 1.0
 **/
@Controller
@RequestMapping("/orSupplier")
public class OrSupplierController {

    @Autowired
    @Qualifier("orSupplierService")
    private OrSupplierService service;

    // 查询所有角色列表
    @RequestMapping(value = "/listAllOrSupplier", method = RequestMethod.GET, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String listAllOrSupplier(HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString(service.listAllOrSuppliers());
    }

    // 通过id查询角色
    @RequestMapping(value = "/findOrSupplierById", method = RequestMethod.GET, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String findOrSupplierById(Long supplierId, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString(service.findOrSupplierById(supplierId));
    }

    // 增加一个角色
    @RequestMapping(value = "/addOrSupplier", method = {RequestMethod.POST,RequestMethod.OPTIONS}, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String addOrSupplier(@RequestBody OrSupplier orSupplier, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString("添加了" + service.addOrSupplier(orSupplier) + "条记录!");
    }

    // 通过id删除一个角色
    @RequestMapping(value = "/deleteOrSupplierById", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String deleteOrSupplierById(@RequestBody Long supplierId, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString("删除了" + service.deleteOrSupplierById(supplierId) + "条记录!");
    }

    // 更新一个角色
    @RequestMapping(value = "/updateOrSupplier", method = RequestMethod.PUT, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String updateOrSupplier(@RequestBody OrSupplier orSupplier, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString("更新了" + service.updateOrSupplier(orSupplier) + "条记录!");
    }
}
